﻿using AnesSystem.Models;
using Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnesSystem
{
    public class AnesRecordUtil : BaseManager<AnesRecordUtil>

    {
        #region Variables
        #endregion

        #region Constructor

        #endregion

        #region Properties

        #endregion

        #region 依赖属性

        #endregion

        #region Event

        #endregion

        #region Private Methods

        #endregion

        #region Public/Protected Methods


        public string GetDrugFullName(PatientDrugsModel patientDrugs)
        {
            StringBuilder name = new StringBuilder();
            DrugsModel drugs = patientDrugs.Drugs;
            if (Constants.DRUG_SPECIAL.Equals(patientDrugs.Type) || Constants.DRUG_FUSU_SPECIAL.Equals(patientDrugs.Type))
            {
                try
                {
                    foreach (var item in drugs.Items)
                    {
                        if (!string.IsNullOrEmpty(name.ToString())) name.Append(" + ");
                        name.Append(item.Name + "(" + (string.IsNullOrEmpty(item.Dose) ? "" : item.Dose) + (string.IsNullOrEmpty(item.Unit) ? "" : item.Unit) + ")");
                    }
                    name.Append(string.IsNullOrEmpty(patientDrugs.Chanel) ? "" : ("(" + patientDrugs.Chanel + ")"));
                    name.Append(string.IsNullOrEmpty(patientDrugs.DrugMethod) ? "" : ("(" + patientDrugs.DrugMethod + ")"));
                    name.Append(string.IsNullOrEmpty(patientDrugs.DrugReason) ? "" : ("(" + patientDrugs.DrugReason + ")"));
                }
                catch (Exception ex)
                {
                    Common.LogHelper.Error(this.GetType(), ex);
                }
                return name.ToString();
            }
            if (patientDrugs.DrugMethod.Equals(Constants.DRUG_XIRU))
            {
                try
                {
                    foreach (var item in drugs.Items)
                    {
                        if (!string.IsNullOrEmpty(name.ToString())) name.Append(" + ");
                        name.Append(item.Name);
                    }
                    name.Append(" " + patientDrugs.DrugSpeeds[0].Unit);
                    name.Append(string.IsNullOrEmpty(patientDrugs.Chanel) ? "" : ("(" + patientDrugs.Chanel + ")"));
                }
                catch (Exception ex)
                {
                    Common.LogHelper.Error(this.GetType(), ex);
                }
            }
            else if (patientDrugs.DrugMethod.Equals(Constants.DRUG_BENGZHU))
            {
                foreach (var item in drugs.Items)
                {
                    try
                    {
                        if (!string.IsNullOrEmpty(name.ToString())) name.Append(" + ");
                        name.Append(item.Name);
                        double dos1 = (string.IsNullOrEmpty(item.Dose) ? "0" : item.Dose).ToDouble();
                        double dos2 = (string.IsNullOrEmpty(patientDrugs.TotalAmount) ? "1" : patientDrugs.TotalAmount).ToDouble();
                        string dos = Math.Round(dos1 / dos2, 2).ToString();
                        string unit = item.Unit + "/" + patientDrugs.TotalAmountUnit;
                        name.Append("(" + dos + unit + ")");
                    }
                    catch (Exception ex)
                    {
                        Common.LogHelper.Error(this.GetType(), ex);
                    }
                }
                name.Append(string.IsNullOrEmpty(patientDrugs.DrugSpeeds[0].Unit) ? "ml/h" : patientDrugs.DrugSpeeds[0].Unit);
                name.Append(string.IsNullOrEmpty(patientDrugs.Chanel) ? "" : ("(" + patientDrugs.Chanel + ")"));
            }
            else if (patientDrugs.DrugMethod.Equals(Constants.DRUG_TCIBENGZHU))
            {
                try
                {
                    foreach (var item in drugs.Items)
                    {
                        if (!string.IsNullOrEmpty(name.ToString())) name.Append(" + ");
                        name.Append(item.Name);
                    }
                    string totleUnit = string.IsNullOrEmpty(patientDrugs.DrugSpeeds[0].Unit) ? "ug/ml" : patientDrugs.DrugSpeeds[0].Unit;
                    name.Append(totleUnit);
                    name.Append(string.IsNullOrEmpty(patientDrugs.Chanel) ? "" : ("(" + patientDrugs.Chanel + ")"));
                }
                catch (Exception ex)
                {
                    Common.LogHelper.Error(this.GetType(), ex);
                }
            }
            else
            {
                try
                {
                    foreach (var item in drugs.Items)
                    {
                        if (!string.IsNullOrEmpty(name.ToString())) name.Append(" + ");
                        name.Append(item.Name);
                        name.Append(item.Unit);
                    }
                    name.Append(string.IsNullOrEmpty(patientDrugs.Chanel) ? "" : ("(" + patientDrugs.Chanel + ")"));
                }
                catch (Exception ex)
                {
                    Common.LogHelper.Error(this.GetType(), ex);
                }
            }
            return name.ToString();
        }
        public string GetDrugHashCode(PatientDrugsModel patientDrugs)
        {
            StringBuilder fullName = new StringBuilder();
            if (Constants.DRUG_XIRU.Equals(patientDrugs.DrugMethod))
            {
                try
                {
                    string unit = patientDrugs.DrugSpeeds[0].Unit;
                    foreach (var item in patientDrugs.Drugs.Items)
                    {
                        fullName.Append(item.Code + unit);
                        List<ConfigDrugsModel> DrugsList = DataManager.Instance.ConfigDrugsModelList.Where(O => O.Deleted == false && O.Code != null && O.Code.Equals(item.Code)).ToList();
                        if (DrugsList == null || DrugsList.Count < 1)
                        {
                            item.Name = item.Code;
                        }
                        else
                        {
                            item.Name = DrugsList.First().Name;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Common.LogHelper.Error(this.GetType(), ex);
                }
            }
            else
            {
                try
                {
                    foreach (var item in patientDrugs.Drugs.Items)
                    {
                        fullName.Append(item.Code + item.Unit);
                        List<ConfigDrugsModel> DrugsList = DataManager.Instance.ConfigDrugsModelList.Where(O => O.Deleted == false && O.Code != null && O.Code.Equals(item.Code)).ToList();
                        if (DrugsList == null || DrugsList.Count < 1)
                        {
                            item.Name = item.Code;
                        }
                        else
                        {
                            item.Name = DrugsList.First().Name;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Common.LogHelper.Error(this.GetType(), ex);
                }
            }
            fullName.Append(patientDrugs.Chanel == null ? "" : patientDrugs.Chanel);
            fullName.Append(patientDrugs.Type);
            return fullName.ToString();
        }

        public string GetTongLiangDrugFullName(PatientDrugsModel patientDrugs)
        {
            StringBuilder name = new StringBuilder();
            DrugsModel drugs = patientDrugs.Drugs;
            if (Constants.DRUG_SPECIAL.Equals(patientDrugs.Type) || Constants.DRUG_FUSU_SPECIAL.Equals(patientDrugs.Type))
            {
                foreach (var item in drugs.Items)
                {
                    if (!string.IsNullOrEmpty(name.ToString())) name.Append(" + ");
                    name.Append(item.Name + "(" + (string.IsNullOrEmpty(item.Dose) ? item.Dose : "") + (item.Unit == null ? "" : item.Unit) + ")");
                }
                return name.ToString();
            }
            if (Constants.DRUG_SHUYE.Equals(patientDrugs.Type))
            {
                try
                {
                    StringBuilder shuYeName = new StringBuilder();
                    foreach (var item in drugs.Items)
                    {
                        if (!string.IsNullOrEmpty(shuYeName.ToString())) shuYeName.Append(" + ");
                        shuYeName.Append(item.Name);
                        shuYeName.Append(item.Dose);
                        shuYeName.Append(item.Unit);
                    }
                    patientDrugs.DrugSpeeds[0].Speed = shuYeName.ToString();
                    name.Append(patientDrugs.Chanel);
                }
                catch (Exception ex)
                {
                    Common.LogHelper.Error(this.GetType(), ex);
                }
                return name.ToString();
            }
            else
            {
                if (patientDrugs.DrugMethod.Equals(Constants.DRUG__IVGTT))
                {
                    foreach (var item in drugs.Items)
                    {
                        if (!string.IsNullOrEmpty(name.ToString())) name.Append(" + ");
                        name.Append(item.Name);
                        name.Append(item.Unit);
                    }
                    name.Append(string.IsNullOrEmpty(patientDrugs.Chanel) ? "" : ("(" + patientDrugs.Chanel + ")"));
                }
                else if (patientDrugs.DrugMethod.Equals(Constants.DRUG_XIRU))
                {
                    foreach (var item in drugs.Items)
                    {
                        if (!string.IsNullOrEmpty(name.ToString())) name.Append(" + ");
                        name.Append(item.Name);
                    }
                    name.Append(" " + patientDrugs.DrugSpeeds[0].Unit);
                    name.Append(string.IsNullOrEmpty(patientDrugs.Chanel) ? "" : ("(" + patientDrugs.Chanel + ")"));
                }
                else if (patientDrugs.DrugMethod.Equals(Constants.DRUG_BENGZHU))
                {
                    foreach (var item in drugs.Items)
                    {
                        if (!string.IsNullOrEmpty(name.ToString())) name.Append(" + ");
                        name.Append(item.Name);
                        double dos1 = (string.IsNullOrEmpty(item.Dose) ? "0" : item.Dose).ToDouble();
                        double dos2 = (string.IsNullOrEmpty(patientDrugs.TotalAmount) ? "1" : patientDrugs.TotalAmount).ToDouble();
                        string dos = Math.Round(dos1 / dos2, 2).ToString();
                        string unit = item.Unit + "/" + patientDrugs.TotalAmountUnit;
                        name.Append("(" + dos + unit + ")");
                    }
                    name.Append(patientDrugs.DrugSpeeds[0].Unit == null ? "ml/h" : patientDrugs.DrugSpeeds[0].Unit);
                    name.Append(string.IsNullOrEmpty(patientDrugs.Chanel) ? "" : ("(" + patientDrugs.Chanel + ")"));

                    //foreach (var item in drugs.Items)
                    //{
                    //    if (!string.IsNullOrEmpty(name.ToString())) name.Append(" + ");
                    //    name.Append(item.Name);
                    //    name.Append(item.Unit);
                    //}
                    //name.Append(patientDrugs.Chanel == null ? "" : "(" + patientDrugs.Chanel + ")");
                }
                else if (patientDrugs.DrugMethod.Equals(Constants.DRUG_TCIBENGZHU))
                {
                    foreach (var item in drugs.Items)
                    {
                        if (!string.IsNullOrEmpty(name.ToString()))
                        {
                            name.Append(" + ");
                        }
                        //string totleDose = patientDrugs.TotalAmount == null ? "" : "(" + patientDrugs.TotalAmount + "ml)";
                        name.Append(item.Name);
                    }
                    string totleUnit = patientDrugs.DrugSpeeds[0].Unit == null ? "ug/ml" : patientDrugs.DrugSpeeds[0].Unit;
                    name.Append(totleUnit);
                    name.Append(string.IsNullOrEmpty(patientDrugs.Chanel) ? "" : ("(" + patientDrugs.Chanel + ")"));
                }
                return name.ToString();
            }

        }

        public string GetTongLiangDrugHashCode(PatientDrugsModel patientDrugs)
        {

            StringBuilder fullName = new StringBuilder();
            if (Constants.DRUG_SHUYE.Equals(patientDrugs.Type))
            {
                foreach (var item in patientDrugs.Drugs.Items)
                {
                    List<ConfigDrugsModel> DrugsList = DataManager.Instance.ConfigDrugsModelList.Where(O => O.Deleted == false && O.Code != null && O.Code.Equals(item.Code)).ToList();
                    if (DrugsList == null || DrugsList.Count < 1)
                    {
                        item.Name = item.Code;
                    }
                    else
                    {
                        item.Name = DrugsList.First().Name;
                    }

                }
                //fullName.Append(patientDrugs.Chanel);
            }
            else
            {
                foreach (var item in patientDrugs.Drugs.Items)
                {
                    fullName.Append(item.Code + item.Unit);
                    List<ConfigDrugsModel> DrugsList = DataManager.Instance.ConfigDrugsModelList.Where(O => O.Deleted == false && O.Code != null && O.Code.Equals(item.Code)).ToList();
                    if (DrugsList == null || DrugsList.Count < 1)
                    {
                        item.Name = item.Code;
                    }
                    else
                    {
                        item.Name = DrugsList.First().Name;
                    }
                }
            }
            fullName.Append(patientDrugs.Chanel == null ? "" : patientDrugs.Chanel);
            fullName.Append(patientDrugs.Type);
            return fullName.ToString();
        }


        public double CalTotalAmounts(List<PatientDrugsModel> patientDrugss)
        {
            double dose = 0;
            //string unit = "";
            if (Constants.DRUG_BENGZHU.Equals(patientDrugss[0].DrugMethod))
            {
                for (int i = 0; i < patientDrugss.Count(); i++)
                {
                    dose += patientDrugss[i].Yongliang.ToDouble();
                    //unit = GetJiLiangUnit(patientDrugss[i]);
                }
            }
            else if (Constants.DRUG__IVGTT.Equals(patientDrugss[0].DrugMethod))
            {
                foreach (var items in patientDrugss)
                {
                    foreach (var item in items.Drugs.Items)
                    {
                        dose += item.Dose.ToDouble();
                    }
                }
                //unit = GetJiLiangUnit(patientDrugss[0]);
            }
            return dose;
        }

        public float CalTotalAmount(PatientDrugsModel patientDrugs)
        {
            double dose = 0;
            if (Constants.DRUG_BENGZHU.Equals(patientDrugs.DrugMethod))
            {
                dose += patientDrugs.Yongliang.ToDouble();
                return (float)dose;
            }
            else if (Constants.DRUG_TCIBENGZHU.Equals(patientDrugs.DrugMethod))
            {
                dose += patientDrugs.TotalAmount.ToDouble();
            }
            else if (Constants.DRUG__IVGTT.Equals(patientDrugs.DrugMethod))
            {
                if (HospitalConfig.Instance.CurrentHospital.HospitalCode.Equals(HospitalConfig.HOSPITAL_CODE_CQ_TLRMYY))
                {
                    foreach (var item in patientDrugs.Drugs.Items)
                    {
                        if (item.Unit != "ml") continue;
                        dose += item.Dose.ToDouble();
                    }
                }
                else
                {
                    foreach (var item in patientDrugs.Drugs.Items)
                    {
                        dose += item.Dose.ToDouble();
                    }
                }
            }
            else
            {
                foreach (var item in patientDrugs.Drugs.Items)
                {
                    dose += item.Dose.ToDouble();
                }
            }
            if (patientDrugs.TakeOut && !string.IsNullOrEmpty(patientDrugs.TakeAmount))
            {
                dose = dose - patientDrugs.TakeAmount.ToDouble();
            }
            return (float)dose;
        }

        public string GetJiLiangUnit(PatientDrugsModel patientDrugs)
        {
            if (HospitalConfig.Instance.CurrentHospital.HospitalCode.Equals(HospitalConfig.HOSPITAL_CODE_CQ_FYBJY))
            {
                if (Constants.DRUG_BENGZHU.Equals(patientDrugs.DrugMethod))
                {
                    return patientDrugs.TotalAmountUnit;
                }
            }
            if (Constants.DRUG_TCIBENGZHU.Equals(patientDrugs.DrugMethod))
            {
                return patientDrugs.TotalAmountUnit;
            }
            if (Constants.DRUG_XIRU.Equals(patientDrugs.DrugMethod)) return null;
            string unit = null;
            foreach (var item in patientDrugs.Drugs.Items)
            {
                string jiLiangUnit = item.Unit;
                if (null == jiLiangUnit) continue;
                if (null == unit)
                {
                    unit = jiLiangUnit;
                }
                else
                {
                    if (!unit.Equals(jiLiangUnit))
                        //单位不一致,默认第一个
                        //unit = patientDrugs.Drugs.Items[0].Unit;
                        return null;
                }
            }
            return unit;
        }

        public double GetJiLiang(PatientDrugsModel patientDrugs)
        {
            double jiLiang = 0;
            foreach (var item in patientDrugs.Drugs.Items)
            {
                double dose = 0;
                if (item.Dose != null && !item.Dose.Equals(""))
                    dose = item.Dose.ToDouble();
                if (dose <= 0) continue;
                if (jiLiang <= 0)
                    jiLiang = dose;
                else
                    jiLiang += dose;
            }
            return Math.Round(jiLiang, 2);
        }

        public double GetRealYeTi(PatientDrugsModel patientDrugs)
        {
            List<DrugSpeedModel> drugSpeeds = patientDrugs.DrugSpeeds;
            DateTime start = new DateTime(); DateTime end;
            double yeti_use = 0;  //已经用掉的液体量
            double sudu = 0; double dos = 0;
            double dos1 = 0; double dos2 = 0;
            foreach (var item in drugSpeeds)
            {
                end = item.BeginTime;
                if (sudu > 0)
                {
                    yeti_use += sudu * GetHoursTime(end, start);
                }
                if (null == item.Speed && Constants.ACTION_PAUSE.Equals(item.Actions))
                    sudu = 0;
                else
                    sudu = item.Speed.ToDouble();
                start = item.BeginTime;
            }
            end = patientDrugs.EndTime;
            if (end == new DateTime())
                end = DataManager.Instance.CurrentPatientLink.Status.OutRoomTime;
            if (end == new DateTime())
                end = DateTime.Now;
            if (sudu > 0)
                yeti_use += sudu * GetHoursTime(end, start);
            if (HospitalConfig.Instance.CurrentHospital.HospitalCode.Equals(HospitalConfig.HOSPITAL_CODE_CQ_TLRMYY))
            {
                foreach (var item in patientDrugs.Drugs.Items)
                {
                    dos1 += (string.IsNullOrEmpty(item.Dose) ? "0" : item.Dose).ToDouble();
                }
                dos2 = (string.IsNullOrEmpty(patientDrugs.TotalAmount) ? "1" : patientDrugs.TotalAmount).ToDouble();
                dos = Math.Round(dos1 / dos2, 2);
                yeti_use = yeti_use * dos;
            }
            return Math.Round(yeti_use, 2);
        }

        //得出实际用药量
        public double GetYaoLiang(PatientDrugsModel patientDrugs)
        {
            if (patientDrugs.TotalAmount == null)
                return 0;
            double yeti = patientDrugs.TotalAmount.ToDouble();
            if (0 == yeti)
                return 0;
            double jiLiang = GetJiLiang(patientDrugs);
            if (jiLiang == 0)
                return 0;
            bool hasSameUnit = true;
            string jiLiangUnit = GetJiLiangUnit(patientDrugs);
            if (null == jiLiangUnit)
                hasSameUnit = false;
            //DateTime time = patientDrugs.EndTime;
            //if (time.Year < 1970) time = DataManager.Instance.CurrentPatientLink.Status.OutRoomTime;
            //if (time.Year < 1970) time = DateTime.Now;
            //if (time.CompareTo(GetPageStartTime()) < 0 
            //    ||time.CompareTo(GetPageEndTime()) > 0) return 0;
            double yeti_use = GetRealYeTi(patientDrugs);
            if (yeti_use != 0)
            {
                if (yeti_use > yeti) yeti_use = yeti;
                if (hasSameUnit)
                    return Math.Round(yeti_use * jiLiang / yeti, 2);
                else
                    return Math.Round(yeti_use, 2);
            }
            return 0;
        }
        private static double GetHoursTime(DateTime end, DateTime start)
        {
            TimeSpan ts1 = new TimeSpan(end.Ticks);
            TimeSpan ts2 = new TimeSpan(start.Ticks);
            TimeSpan ts3 = ts1.Subtract(ts2).Duration();
            //你想转的格式
            return Math.Round(ts3.TotalHours, 2);
        }

        public void CalOutTotal()
        {
            if (HospitalConfig.Instance.CurrentHospital.HospitalCode.Equals(HospitalConfig.HOSPITAL_CODE_CQ_NTZYY))
            {
                PatientLinkModel p = DataManager.Instance.CurrentPatientLink;
                if (p == null) return;
                double zcl = p.AnesthesiaRecord.LiquidInAndOut.Sxl.ToDouble()
                    + p.AnesthesiaRecord.LiquidInAndOut.NiaoLiang.ToDouble()
                    + p.AnesthesiaRecord.LiquidInAndOut.QtclNT.ToDouble();
                p.AnesthesiaRecord.LiquidInAndOut.Zcl = zcl.ToString();
            }
        }

        public void CalInTotal()
        {
            PatientLinkModel p = DataManager.Instance.CurrentPatientLink;
            if (p == null) return;
            double zrl = p.AnesthesiaRecord.LiquidInAndOut.ZongShuRuLiang.ToDouble()
                + p.AnesthesiaRecord.LiquidInAndOut.Bzrl.ToDouble()
                + p.AnesthesiaRecord.LiquidInAndOut.QtrlNT.ToDouble();
            p.AnesthesiaRecord.LiquidInAndOut.Zrl = zrl.ToString();
        }
        public void CalContinueLiquidInAndOut()
        {
            List<PatientDrugsModel> patientDrugList = OperationDataPool.Instance.CurOperationData.DrugsDataCache.AllPatientDrugsList.ToList();
            double bzrl = 0;
            foreach (var items in patientDrugList)
            {
                if ("invalid".Equals(items.Status) || !Constants.DRUG_SHUZHONG.Equals(items.Type)) continue;
                if (Constants.DRUG_BENGZHU.Equals(items.DrugMethod))
                {
                    items.Yongliang = GetYaoLiang(items).ToString();
                    OperationDataPool.Instance.CurOperationData.DrugsDataCache.AddAndUpdateExe(items);
                    double dos = 0;
                    double dos1 = 0;
                    double yongLiang = 0;
                    foreach (var item in items.Drugs.Items)
                    {
                        dos1 += item.Dose.ToDouble();
                    }
                    double dos2 = items.TotalAmount.ToDouble();
                    dos = Math.Round(dos1 / dos2, 2);
                    yongLiang = dos == 0 ? 0 : items.Yongliang.ToDouble() / dos;
                    bzrl += yongLiang;
                }
                else if (Constants.DRUG_TCIBENGZHU.Equals(items.DrugMethod))
                {
                    bzrl += CalTotalAmount(items);
                }
            }
            DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.LiquidInAndOut.Bzrl = bzrl.ToString();
        }

        public void CalSingleLiquidInAndOut()
        {
            List<PatientDrugsModel> patientDrugList = OperationDataPool.Instance.CurOperationData.DrugsDataCache.AnesSpecialDrugList.ToList();
            double yongLiang = 0;
            foreach (var items in patientDrugList)
            {
                if ("invalid".Equals(items.Status) || Constants.DRUG_BEIYONG.Equals(items.DrugReason)) continue;
                foreach (var item in items.Drugs.Items)
                {
                    yongLiang += item.Dose.ToDouble();
                }
            }
            DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.LiquidInAndOut.QtrlNT = yongLiang.ToString();
        }
        public void CalLiquidInAndOutByType()
        {
            double yeti = 0;
            double phy = 0; double jiaotiye = 0;
            double rbc = 0; double xuejiang = 0;
            double jty = 0; double zongShuRuLiang = 0;
            foreach (var items in OperationDataPool.Instance.CurOperationData.DrugsDataCache.AnesInfusionMapCodeList)
            {
                foreach (var item in items.Value)
                {
                    if ("invalid".Equals(item.Status) || !Constants.DRUG__IVGTT.Equals(item.DrugMethod)) continue;
                    yeti = CalYeTiYongLiang(item);
                    switch (item.LiquidType)
                    {
                        case "平衡液":
                            {
                                phy += yeti;
                            }
                            break;
                        case "晶体液":
                            {
                                jty += yeti;
                            }
                            break;
                        case "胶体液":
                            {
                                jiaotiye += yeti;
                            }
                            break;
                        case "红细胞悬液":
                            {
                                rbc += yeti;
                            }
                            break;
                        case "血浆":
                            {
                                xuejiang += yeti;
                            }
                            break;
                    }
                    zongShuRuLiang += yeti;
                }
            }
            DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.LiquidInAndOut.Phy = phy == 0 ? "" : phy.ToString();
            DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.LiquidInAndOut.JiaoTiYe = jiaotiye == 0 ? "" : jiaotiye.ToString();
            DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.LiquidInAndOut.JingTiYe = jty == 0 ? "" : jty.ToString();
            DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.LiquidInAndOut.Rbc = rbc == 0 ? "" : rbc.ToString();
            DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.LiquidInAndOut.XueJiang = xuejiang == 0 ? "" : xuejiang.ToString();
            DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.LiquidInAndOut.ZongShuRuLiang = zongShuRuLiang == 0 ? "" : zongShuRuLiang.ToString();

        }

        public double CalYeTiYongLiang(PatientDrugsModel p)
        {
            double yongLiang = 0;
            string jiLiangUnit = GetJiLiangUnit(p);
            if (jiLiangUnit == null)
            {
                return 0;
            }
            foreach (var item in p.Drugs.Items)
            {
                yongLiang += item.Dose.ToDouble();
            }
            if (!string.IsNullOrEmpty(p.TakeAmount))
            {
                yongLiang = yongLiang - p.TakeAmount.ToDouble();
            }
            return yongLiang;
        }

        #endregion

        #region EventHandlers

        #endregion
    }
}
